<?php
/**
 * File: iHackyFunctions.php
 * 
 * This file contains most of the functions that is used 
 * throughout the application.  
 */
/**
 * 
 */
include 'messageboxclass.php';
/**
 * Get a database connection specified by the config.php properties.
 *
 * @return A database connection object.
 */
function getDbConn() {
	$db = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_user'], $GLOBALS['db_pass'])
	   or DIE('Error: Unable to connect to SQL Database');
	mysql_select_db($GLOBALS['db_name'], $db);
	return $db;
}

/**
 * Function to close a connection with database specified by argument.
 *
 * @param Object $conn The connection object to close.
 */
function closeDb($conn) {
	mysql_close($conn);
}

/**
 * Prints the fbml tags to set the page title.
 *
 */
function printTitle() {
	echo '<fb:title>
          Welcome to iHacky!
        </fb:title>';
}

/**
 * Prints fbml tags to render the dashboard.
 *
 */
function printDashboard() {
	echo '
        <fb:dashboard decoration="no_padding">
            <fb:action href="http://code.google.com/p/ihacky/">iHacky Homepage</fb:action>
            <fb:action href="http://depfind.sourceforge.net/">DependencyFinder Homepage</fb:action>
            <fb:help href="http://code.google.com/p/ihacky/wiki/iHackyFAQS">Need Help?</fb:help>
            <fb:create-button
                href="http://code.google.com/p/hackystat/">Learn More About Hackystat!
            </fb:create-button>
        </fb:dashboard>
        ';
}

/**
 * Prints the HTML form for the class search box.
 *
 */
function printSearchTable() {
    echo '<span style="display:none"><fb:editor></fb:editor></span>
        <form id="search_form">
            <table class="editorkit" border="0" cellspacing="0" style="width:400px">
            <tr class="width_setter">
                <th style="width:50px"></th>
                <td></td>
            </tr>
            <tr>
                <th class="detached_label">
                    <label>Expertise Search:</label>
                </th>
                <td class="editorkit_row">
                    <input type="text" name="userInput"/> 
                </td>
                <th class="detached_label">
                    <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rank:</label>
                </th> 
                <td class="editorkit_row"> 
                    <select name="rank">  
                       <option value="1">1</option>  
                       <option value="2">2</option>  
                       <option value="3">3</option>
                       <option value="4">4</option>
                       <option value="5">5</option>  
                    </select>               
                </td>
                <td class="right_padding"></td>
            </tr>
            <tr>
                <th></th>
                <td class="editorkit_buttonset">
                    <input type="submit" class="editorkit_button action" value="Search"  
                              clickrewriteurl="http://www.ikoaguild.com/ihacky/"
                              clickrewriteform="search_form" 
                              clickrewriteid="content"
                              clicktoshow="loadIcon"/>
                </td>
                <td class="right_padding"></td>
            </tr>
            </table>
        </form>
        <div id="content">
            <div align="center">
                <img src="http://www.ikoaguild.com/ihacky/images/ajax-loader.gif" id="loadIcon"
                    style="display:none;" />  
            </div>
        </div>
        ';
}

/**
 * Prints the java script to make DIV sections collapse and uncollapse.
 *
 */
function printJavaScriptDiv(){
	echo "<script type=\"text/javascript\">
        function showdiv(id) {
           var elm = document.getElementById(id);
  
           if(elm.getStyle('display') == 'block') {
             Animation(elm).to('height', '0px').to('opacity', 0).hide().ease(Animation.ease.end).go(); 
             return false;
           }
           else {
             Animation(elm).to('height', 'auto').to('opacity', 1).show().ease(Animation.ease.end).go(); 
             return false;
           }
        }
        </script>";
}

/**
 * Prints the FBML tags to render navigation tabs. A integer is passed in
 * to indicate which tab is highlighted.
 *
 * @param Int $selection selection of the position number of tab to highlight starting from left.
 */
function printFbmlTabs($selection){
	$firstTab = "false";
	$secontTab = "false";
	$thirdTab = "false";
	$fourthTab = "false";
	$fifthTab = "false";

	switch ($selection){
		case 1:
			$firstTab = "true";
			break;
		case 2:
			$secontTab = "true";
			break;
		case 3:
			$thirdTab = "true";
			break;
		case 4:
			$fourthTab = "true";
			break;
		case 5:
			$fifthTab = "true";
			break;
		default:
			echo 'No highlighted tab selected.';
	}
	echo "<fb:tabs>
	<fb:tab-item href=\"index.php\" title=\"HOME\" selected=\"$firstTab\" />
	<fb:tab-item href=\"profile.php\" title=\"PROFILE\" selected=\"$secontTab\" />
	<fb:tab-item href=\"invite.php\" title=\"INVITE\" selected=\"$thirdTab\"/>
	<fb:tab-item href=\"messagebox.php\" title=\"MESSAGE BOX\" selected=\"$fourthTab\"/>
	</fb:tabs>";
}

/**
 * Prints the hackystat info add form.  The form utilizes FBML mock ajax
 * functionality with the attributes clickrewriteurl, clickrewriteform,
 * clickrewriteid, clicktoshow and clicktohide.
 *
 */
function printAddForm(){
	echo '<span style="display:none"><fb:editor></fb:editor></span>      
        <form id="add_form">
            <font color="#666666">Enter Hackystat info here:</font><br>
                Username:
            <input name="hackystat_id" type="text">
            <br/>
                Password:
            <input name="hackystat_password" type="password"/>
            <br/>
            <table class="editorkit" border="0">
                <td class="editorkit_buttonset">
                <input type="submit" class="editorkit_button action" value="Submit"  
                    clickrewriteurl="http://www.ikoaguild.com/ihacky/"
                    clickrewriteform="add_form" 
                    clickrewriteid="registerContent"
                    clicktoshow="add_spinner"
                    clicktohide="add_form"/>
                </td>
                </table>
        </form>
       
        <div id="registerContent">
            <div align="center"
                <img src="http://www.ikoaguild.com/ihacky/images/ajax-loader.gif" id="add_spinner" 
                    style="display:none;"/>
            </div>
        </div>'; 
}

/**
 * Prints the classes associated with the user.
 * 
 * @param $facebook The facebook ID of the user to display
 * @param bool $isProfileOwner whether the current user is owner
 */
function showClasses($facebookId, $isProfileOwner) {
	// Open database connection
	$conn = getDbConn();

	if($isProfileOwner) {
		 
		$pageNum = 1;
		$rowsPerPage = 25;
		if(isset($_REQUEST['page'])){
			$pageNum = $_REQUEST['page'];
		}

		$offset = ($pageNum - 1) * $rowsPerPage;

		$qryGetClassesCount = "SELECT cls.class_detail AS \"Class\", cu.class_rank AS \"Expertise Rank\",
		cu.class_id AS \"classID\"
		FROM CLASS_USERS cu JOIN CLASS cls ON (cu.class_id = cls.class_id)
		WHERE cu.facebook_id = $facebookId
		ORDER BY cu.class_rank DESC";
		 
		$rowCount = mysql_query($qryGetClassesCount, $conn) or DIE(mysql_error());
		$numRows = mysql_num_rows($rowCount);
		$maxPage = ceil($numRows/$rowsPerPage);

		$queryGetClasses = "SELECT cls.class_detail AS \"Class\", cu.class_rank AS \"Expertise Rank\",
		cu.class_id AS \"classID\"
		FROM CLASS_USERS cu JOIN CLASS cls ON (cu.class_id = cls.class_id)
		WHERE cu.facebook_id = $facebookId
		ORDER BY cu.class_rank DESC
		LIMIT $offset, $rowsPerPage";

		$result = mysql_query($queryGetClasses);

		if($pageNum == $maxPage){
			$lastItem = $offset + ($numRows - (($pageNum - 1) * $rowsPerPage));
		}
		else{
			$lastItem = ($offset + $rowsPerPage);
		}
		$offset++;

		echo "
            <div class=\"header\">
            <h3><a href=\"#\" onclick=\"showdiv('Classes');\">Classes</a></h3>
            </div>
            <div id=\"Classes\" style=\"display: none\"> <br>
            These are classes you have used that were found in the Hackystat sensorbase and your
            default rank is determined by the number of dev events associated with that class. You
            increase in rank for every 10 dev events. You can manually change your rank and you can 
            set your rank to 0 so it doesn't show up in searches.
            <br><br>
            ";

		echo "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
            <tr>
                <td><b>Classes</b></td>
                <td><b>Expertise Rank</b></td>
            ";

		while ($row = mysql_fetch_array($result)) {
			echo "
			<form name=\"changeRankForm\" method=\"post\" action=\"rank_change.php\">
			<tr>
			<input name=\"id\" type=\"hidden\" value=\"$facebookId\">
			<input name=\"class\" type=\"hidden\" value=\"".$row['classID']."\">
                        <td>".$row['Class']."</td>
                        <td><center>                    
                            <select name=\"rank\">";
			for( $i = 0; $i <= 5; $i++) {
				if ($row['Expertise Rank'] == $i) {
					echo "<option value=\"$i\" selected=\"selected\"> $i
					</option>";
				}
				else {
					echo "<option value=\"$i\"> $i </option>";
				}
			}
			echo "
                            </select><input type=\"submit\" value=\"Change Rank\"></center>                  
                        </td>
                    </tr>
                </form>
            ";
		}
		echo "</table>";
		echo "</div><br>";
		if($pageNum == 1 && ($numRows > $rowsPerPage)){
			$newPageNum = $pageNum + 1;
			echo '<br><br>';

			echo "<div align=\"center\">
			<form id=\"first_page\">

			<input name=\"page\" type=\"hidden\" value=\"$newPageNum\">
			<a clickrewriteurl=\"http://www.ikoaguild.com/ihacky/rank_change.php\"
			clickrewriteform=\"first_page\"
			clickrewriteid=\"content\"
			clicktoshow=\"loadIcon\">
			Next
			<img src=\"http://www.ikoaguild.com/ihacky/images/forwardarrow.png\" align=\"top\">
			</a>
			</form>
			</div>";
			 
		}
		else if($pageNum < $maxPage){
			echo '<br><br>';
			$previousPageNum = $pageNum - 1;
			echo "<div align=\"center\">
			<table>
			<tr>
			<td>
			 
			<form id=\"pre_page\">
			 
			<input name=\"page\" type=\"hidden\" value=\"$previousPageNum\">

			<a clickrewriteurl=\"http://www.ikoaguild.com/ihacky/rank_change.php\"
			clickrewriteform=\"pre_page\"
			clickrewriteid=\"content\"
			clicktoshow=\"loadIcon\">
			<img src=\"http://www.ikoaguild.com/ihacky/images/reversearrow.png\" align=\"top\">
			Previous
			</a>
			</form>

			</td>";
			$nextPageNum = $pageNum + 1;
			echo "<td>

			<form id=\"next_page\">

			<input name=\"page\" type=\"hidden\" value=\"$nextPageNum\">
			<a clickrewriteurl=\"http://www.ikoaguild.com/ihacky/rank_change.php\"
			clickrewriteform=\"next_page\"
			clickrewriteid=\"content\"
			clicktoshow=\"loadIcon\">
			Next
			<img src=\"http://www.ikoaguild.com/ihacky/images/forwardarrow.png\" align=\"top\">
			</a>
			</form>
			 
			</td>
			</tr>
			</table>
			</div>";
		}
		else if($pageNum == $maxPage && ($numRows > $rowsPerPage)){
			echo '<br><br>';
			$newPageNum = $pageNum - 1;
			echo "<div align=\"center\">
			<form id=\"last_page\">
			 
			<input name=\"page\" type=\"hidden\" value=\"$newPageNum\">

			<a clickrewriteurl=\"http://www.ikoaguild.com/ihacky/rank_change.php\"
			clickrewriteform=\"last_page\"
			clickrewriteid=\"content\"
			clicktoshow=\"loadIcon\">
			<img src=\"http://www.ikoaguild.com/ihacky/images/reversearrow.png\" align=\"top\">
			Previous
			</a>
			</form>
			</div>";
		}
	}
	else {
		$queryGetClasses = "SELECT cls.class_detail AS \"Class\", cu.class_rank AS \"Expertise Rank\"
		FROM CLASS_USERS cu JOIN CLASS cls ON (cu.class_id = cls.class_id)
		WHERE cu.facebook_id = $facebookId
		ORDER BY cu.class_rank DESC";

		$result = mysql_query($queryGetClasses);

		echo "
            <div class=\"header\">
            <h3><a href=\"#\" onclick=\"showdiv('Classes');\">Classes</a></h3>
            </div>
            <div id=\"Classes\" style=\"display: none\"> 
            ";

		echo "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
            <tr>
                <td>Classes</td>
                <td>Times Used</td>
                <td>Expertise Rank</td>
            ";

		while ($row = mysql_fetch_array($result)) {
			if ($row['Expertise Rank'] != '0') {
				echo "
                    <tr>
                        <td>".$row['Class']."</td>
                        <td>".$row['Times Used']."</td>
                        <td>".$row['Expertise Rank']."</td>
                    </tr>
                ";
			}
		}
		echo "</table>";
		echo "</div><br>";
	}
	// Close database connection.
	closeDb($conn);
}

/**
 * Prints the Expertise Browser feature. 
 */
function showExpertiseTagCloud() {
	echo "
        <div class=\"header\">
            <h3><a href=\"#\" onclick=\"showdiv('CommunityExpertise');\">Expertise Browser</a></h3>
        </div>
        <div id=\"CommunityExpertise\" style=\"display: none\">
        
        ";
	   expertiseTagCloud();
	echo "
       
        </div><br>
        ";
}

/**
 * Queries the database for all classes over rank 0 and stores each class as a key and a count of
 * all unique users associated with that class in a hashmap for a tag cloud.  Afterwards, it creates
 * an array of links where the key is the text and the count is the text size.
 *
 * @return Array of html links
 */
function expertiseTagCloud() {
	// Open database connection
	$conn = getDbConn();

	$counter = 1;
	$queryClassUsersCount = "SELECT cls.class_detail AS \"tag detail\", cls.class_name as tag,
        COUNT( cu.facebook_id ) AS count
        FROM CLASS_USERS cu 
        JOIN CLASS cls ON ( cu.class_id = cls.class_id )
        WHERE cu.class_rank != 0
        GROUP BY cls.class_name
        ORDER BY cls.class_name ASC";

	$result = mysql_query($queryClassUsersCount, $conn) or DIE(mysql_error()."pathTagCloud");

	// Iterate through results and store in an array in order to calculate the font size of each tag
	while ($row = mysql_fetch_array($result)) {
		//$tags[$row['tag']] = $row['count'];

		// Break up package path with period as delimiter
		$tagDetailArray = explode(".", $row['tag detail']);
		// Remove the class name from the package path
		$poppedIndex = array_pop($tagDetailArray);
		// Reconstruct package path without class name
		$tagDetailString = implode(".", $tagDetailArray);

		// Do not include classes with non alphabetic characters.
		if (preg_match("/[^A-Za-z]/", $poppedIndex) == 0) {
			$tags[$row['tag']] = $row['count'];

			// Count the number of classes in the package
			if (!array_key_exists($tagDetailString, $tagsDetail)) {
				$tagsDetail[$tagDetailString] = 1;
			}
			else {
				$tagsDetail[$tagDetailString]++;
			}
		}
	}
	//print_r($tagsDetail);

	// Close database connection.
	closeDb($conn);

	//preg_match("/.[A-Za-z0-9]/", $row['tag']);
	// Font size range
	$maxSize = 32; // Max font size in px
	$minSize = 10; // Min font size in px

	// Get the largest and smallest array values
	$maxCount = max(array_values($tagsDetail));
	$minCount = min(array_values($tagsDetail));

	// Find the range of values
	$range = $maxCount - $minCount;
	// Prevent division by zero.
	if (0 == $range) {
		$range = 1;
	}

	// Determine the font-size increment
	// This is the increase per tag quantity (times used)
	$increment = ($maxSize - $minSize) / ($range);

	$cloud_html = '';
	$cloud_tags = array();

	// Iterate through tag array
	foreach ($tagsDetail as $key => $value) {
 
		// Calculate the font size
		//$size = $minSize + ($value - $minCount) * ($maxSize - $minSize) / $spread;
		$size = $minSize + (($value - $minCount) * $increment);

		echo '
		<form id="'.$counter.'">       
        <input name="tagsDetailInput" type="hidden" value="' . $key . '" />
        <a  clickrewriteurl="http://www.ikoaguild.com/ihacky/classTagCloud.php" 
            clickrewriteform="'.$counter.'" 
            clickrewriteid="CommunityExpertise" 
            style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" 
            title="There are ' . $value . ' known classes in the \'' . $key  . '\' package">'
            . $key .
        '</a>
        </form>';
		$counter++;
	}

	//$cloud_html = join("\n", $cloud_tags) . "\n";

	//return $cloud_html;
}

/**
 * Function to check if current user is already in iHacky database.
 *
 * @param Int $user The facebook ID to match iHacky database ID.
 * @return Boolean Returns true if user exist in iHacky database, false otherwise.
 */
function checkUserExist($user) {
	$conn = getDbConn();

	// create query to see if user is already in the database.
	$qryGetUserID = "SELECT facebook_id,hackystat_id,AES_DECRYPT(hackystat_password,'414')
	   FROM USERS WHERE $user = facebook_id";
	$resultUserID = mysql_query($qryGetUserID, $conn) or DIE(mysql_error());
	$userArray = mysql_fetch_array($resultUserID);

	closeDb($conn);
	if (!$userArray) {
		return false;
	}
	else {
		return true;
	}
}

/**
 * Class to create a new message object.
 *
 */
class Message
{
	private $sender;
	// var $recipients = array();
	private $recipient;
	private $messageSubject = " ";
	private $messsageBody = " ";
	private $errorData = " ";
	private $timeSent = 0;
	private $status = 0;
	private $messageHandler = "store_message.php"; // default page to POST to

	//public function __construct($sender, $recipient, $messageSubject, $messageBody, $errorData, $timeSent, $messageHandler)
	public function __construct($sender, $recipient, $messageSubject, $messageBody, $timeSent, $status, $messageHandler)
	{
		$this->sender = $sender;
		$this->recipient = $recipient;
		$this->messageSubject = $messageSubject;
		$this->messageBody = $messageBody;
		//$this->errorData = $errorData;
		$this->timeSent = $timeSent;
		$this->status = $status;
		$this->messageHandler = $messageHandler;

	}

	// TODO: need to find way to get rid of forward slashes encoding.
	// creates a message composer using HTML form.
	public function createMessageForm()
	{
		//if(isset($this->sender) && isset($this->recipient) && isset($this->errorData) && isset($this->messageHandler))
		if(isset($this->sender) && isset($this->recipient) && isset($this->messageHandler))
		{
			echo "<form name=\"message\" method=\"post\" action=\"$this->messageHandler\">";
			echo "<table>";

			echo "<tr>";
			echo "<td style=\"width: 100px; background-color: #EEEEEE; \">From:</td>";
			echo "<td style=\"width: 100px; \"><fb:name useyou=\"false\" uid=\"$this->sender\" /></td>";
			echo "<td><input name=\"sender\" readonly=\"true\" type=\"hidden\" size=\"12\" value=\"$this->sender\" ></td>";
			echo "</tr>";

			echo "<tr>";
			echo "<td style=\"width: 100px; background-color: #EEEEEE; \">To: </td>";
			echo "<td style=\"width: 100px; \"><fb:name useyou=\"false\" uid=\"$this->recipient\" /></td>";
			echo "<td><input name=\"recipient\" readonly=\"true\" type=\"hidden\" size=\"12\" value=\"$this->recipient\" ></td>";
			echo "</tr>";

			echo "<tr>";
			echo "<td style=\"width: 100px; background-color: #EEEEEE; \">Subject:</td>";
			echo "<td><input name=\"messageSubject\" type=\"text\" style=\"width: 300px\" size=\"12\" value=\"$this->messageSubject\" ></td>";
			echo "</tr>";

			echo "<tr>";
			echo "<td style=\"width: 100px; background-color: #EEEEEE;\" align=\"left\" valign=\"top\">Message:</td>";
			echo "<td><textarea name=\"messageBody\" cols=\"60\" rows=\"10\">" . $this->messageBody . "</textarea></td>";
			echo "</tr>";

			echo "<tr align=\"center\">";
			echo "<td>&nbsp;&nbsp;&nbsp;</td>";
			echo "<td>";
			echo "<input type=\"submit\" name=\"submit\" style=\"width: 100px\" value=\"Send\">";
			echo "<input type=\"submit\" name=\"cancel\" style=\"width: 100px\" value=\"Cancel\">";
			echo "</td>";
			echo "</tr>";
			/*
			 echo "<tr>";
			 echo "<td style=\"width: 100px; background-color: #EEEEEE; \">Source:</td>";
			 echo "<td><textarea name=\"errorData\" cols=\"60\" rows=\"5\">" . $this->errorData . "</textarea></td>";
			 echo "</tr>";
			 */
			echo "</table>";
			echo "</form>";

			return 1;
		}
		else
		{
			//echo "ERROR: Unable to generate message. Undefined field.";
			//return 0;
		}

	}

	// TODO: create setter and getter functions for the fields.

} // end class

/**
 * Function to print the banner on each page. Different information
 * is displayed depending if the user exist in the iHacky database.
 *
 * @param Int $user The facebook ID of the current user
 */
function printBanner($user){
	$check = checkUserExist($user);
	$classCount = getNumUserClasses($user);


	echo '<table width="100%" border="0">';
	echo '<tr>';
	echo '<td style="width: 70%; height: 130px;">';
	if(!$check){
		 
		echo '<div align=center>
                   <font color="#666666"><b>Welcome to iHacky!</b><br>
                   Join the iHacky community! and share your knowledge about the classes you use in 
                   your Java applications!<br>
                   All you need is the Hackystat framework and DependencyFinder!<br><br>
                   Seeking help on a Java class?  Just type the Java class name into the search box!<br>
                   </font><br>
            ';    
	}
	else{
		
		$messageBox2 = new MessageBox($user);
        $messageBoxSize2 = $messageBox2->listMessages(false);
        $messageUnread2 = $messageBox2->getNumberOfNewMessages();
        
		echo "<div align=center>
		<font color=\"#666666\">
		<b>Welcome Back!</b><br>
		You have $classCount total classes that you know!<br>
        There are $messageBoxSize2 message(s) total in your inbox. $messageUnread2 unread.<br><br> 
		Seeking help about a certain Java class?<br>
		Just type the Java class name into the search box and view its members!<br>
		 
		</font>
		</div>";
	}

	echo '</td>';
	echo '<td class="editorkit_buttonset">';


	if(!$check){
		printAddForm();
	}
	else{
		echo "<div align=\"center\"><b>Hi
		<fb:name firstnameonly=\"true\" uid=\"$user\" useyou=\"false\" linked=\"false\"/>!
		</b></div><br>";

		echo "<div align=\"center\">
		<fb:profile-pic uid=\"$user\" size=\"small\" linked=\"false\" />";
		echo "</div>";
	}


	echo    '</td>
    </tr>
</table><br><br>';
}

/**
 * Function to test the hackystat login data of the user
 *
 * @param $URI The hackystat URI to test login
 * @param String $username The user's hackystat username
 * @param String $password The user's hackystat password
 * @return Bool True if the data is valid, false otherwise
 */
function testLogin($URI, $username, $password){

	// create a new curl resource
	$curlObject = curl_init();

	// set URL and other appropriate options
	curl_setopt($curlObject, CURLOPT_URL,$URI);
	curl_setopt($curlObject, CURLOPT_HEADER, 0);
	curl_setopt($curlObject, CURLOPT_USERPWD, $username.":".$password);
	curl_setopt($curlObject, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curlObject, CURLOPT_VERBOSE, 1);

	// grab URL and pass it to the browser
	curl_exec($curlObject);
	curl_error($curlObject);

	if(curl_getinfo($curlObject, CURLINFO_HTTP_CODE) < 300) {
		return true;
	}
	else {
		return false;
	}

	// close curl resource, and free up system resources
	curl_close($curlObject);
	 
}

/**
 * Function to get the number of classes associated with the user
 *
 * @param Int $user The facebook ID of the current user
 * @return Int $count The count of the number of classes associated with user
 */
function getNumUserClasses($user){

	$conn = getDbConn();

	$qryGetNumUserClasses = "Select * FROM CLASS_USERS WHERE facebook_id = $user
	AND class_rank != '0'";

	$result = mysql_query($qryGetNumUserClasses, $conn) or DIE(mysql_error());


	$count = mysql_num_rows($result);
	closeDb($conn);
	return $count;

}

/**
 * Prints the mock ajax FORM to edit the user's hackstat login info
 *
 */
function editHackystatInfo() {
	echo "
        <div class=\"header\">
            <h3><a href=\"#\" onclick=\"showdiv('HackyInfo');\">Hackystat Information</a></h3>
        </div>
        <div id=\"HackyInfo\" style=\"display: none\"> 
            <table border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
                <form id=\"editForm\">
                    <tr>
                        <td>Username: </td>
                        <td><input type=\"text\" name=\"Username\" /></td>
                    </tr>
                    <tr>
                        <td>Password: </td>
                        <td><input type=\"password\" name=\"Password\" /></td>
                    </tr>
                    <tr>
                        <td><input type=\"submit\" value=\"Edit\" 
                            clickrewriteurl=\"http://www.ikoaguild.com/ihacky/profile.php\"
                            clickrewriteform=\"editForm\"
                            clickrewriteid=\"HackyInfo\"/>
                        </td>
                    </tr>
                </form>
            </table>
        </div><br>
        ";
}
?>